package main

import (
	"fmt"
)

/**
执行用时：4 ms, 在所有 Go 提交中击败了98.49%的用户
内存消耗：3.9 MB, 在所有 Go 提交中击败了59.79%的用户
 */
func searchRange(nums []int, target int) []int {

	if len(nums) == 0 { return []int{-1, -1} }

	l, r := 0, len(nums) - 1
	for l < r {
		mid := (l + r) >> 1
		if nums[mid] >= target {
			r = mid
		} else {
			l = mid + 1
		}
	}

	if nums[l] != target { return []int{-1, -1} }

	L := l
	l, r = 0, len(nums) - 1
	for l < r {
		mid := (l + r + 1) >> 1
		if nums[mid] <= target {
			l = mid
		} else {
			r = mid - 1
		}
	}

	return []int{L, r}
}

func main() {

	nums := []int{5, 7, 7, 8, 8, 10}
	fmt.Println(searchRange(nums, 8))
}
